package com.project.controller;


import com.project.entity.Business;
import com.project.mapper.TOrderMapper;
import com.project.service.IBusinessService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhangyang
 * @since 2021-10-06
 */
@RestController
@RequestMapping("/business")
@Api("商家控制接口")
public class TBusinessController {

    @Autowired
    private IBusinessService businessService;
    @Autowired
    private TOrderMapper orderMapper;

    @GetMapping("/findByItem")
    public List<Business> findByItem(String shopowner,
                                     String name,
                                     String status,
                                     LocalDate start,
                                     LocalDate end) {
        List<Business> byItem = businessService.findByItem(shopowner, name, status, start, end);
        for (int i = 0; i < byItem.size(); i++) {
            Business business = byItem.get(i);
            Business business1 = orderMapper.findBusiness(business.getCode());
            business.setOrderNum(business1.getOrderNum());
            business.setOrderMoney(business1.getOrderMoney());
            byItem.set(i, business);
        }
        return byItem;
    }

    @GetMapping("/findById")
    public Business findById(String id) {
        return businessService.findById(id);
    }
}
